import { Empty } from 'antd'
import React from 'react'
import QuestionForm from './QuestionForm'

type Props = {
  params: { id: string }
}

export default async function Page(props: Props) {
  const { id } = props.params
  // 根据id获取问卷信息
  const data = await fetch(
    'http://localhost:3003/question/getInfo?_id=' + id
  ).then(response => response.json())

  const { isDelete, publish, componentsList } = data.data

  if (isDelete !== 0) {
    return (
      <div className="h-[100vh] flex justify-center items-center">
        <Empty description="问卷已删除" />
      </div>
    )
  }

  if (!publish) {
    return (
      <div className="h-[100vh] flex justify-center items-center">
        <Empty description="问卷未发布" />
      </div>
    )
  }

  return <QuestionForm componentsList={componentsList} questionId={id} />
}
